package com.sx.micowell.module.train.setting

import android.widget.Toast
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.base.BaseActivity
import com.example.mvvm.base.data.DataBindingConfig
import com.example.mvvm.until.Tips
import com.example.mvvm.until.ToastUtils
import com.miloyu.modelnet.response.TrainListVO
import com.miloyu.modelnet.response.log
import com.sx.micowell.BR
import com.sx.micowell.R
import com.sx.micowell.databinding.FragTrainStepSettingBinding
import com.sx.micowell.framework.adapter.TrainSettingAdapter
import com.sx.micowell.framework.app.IntentKey
import com.sx.micowell.framework.app.MyFragment
import com.sx.micowell.framework.arouth.RoutePath
import com.sx.micowell.framework.entity.PlanSettingBean
import com.sx.micowell.framework.model.PlanModel
import com.sx.micowell.framework.model.TrainSettingModel

/**
 * @Description
 * @Author 梁浩文
 * @Date 2021/9/1 9:18
 */
@Route(path = RoutePath.TRAIN_STEP_SETTING)
class TrainStepSettingFragment : MyFragment<FragTrainStepSettingBinding, BaseActivity<*>>() {

    @Autowired(name = IntentKey.ID)
    lateinit var ids: String
    private val viewModel: TrainSettingModel by lazy {
        getFragmentScopeViewModel(TrainSettingModel::class.java)
    }
    private lateinit var lisenter: (PlanSettingBean) -> Unit?;

    fun setOnLabelCheckedListener(e: (PlanSettingBean) -> Unit) {
        this.lisenter = e
    }
    override fun getDataBindingConfig(): DataBindingConfig =
        DataBindingConfig(R.layout.frag_train_step_setting, BR.viewModel, viewModel)
            .addBindingParam(BR.adapter,
                TrainSettingAdapter(context, viewModel.selectTrainSettingList)
                    .also {
                        it.setOnItemClickListener { viewId, item, position ->
                            if(viewModel.selectTrainSettingList.contains(item)){
                                viewModel.selectTrainSettingList.remove(item)
                            }else{
                                viewModel.selectTrainSettingList.add(item)
                            }
                            it.submitList(viewModel.trainSettingList.value)
                        }
                    })

    override fun initView() {

    }

    override fun initData() {
        viewModel.reqActionList(ids)
    }

    fun getSelectBean(){
        if (viewModel.selectTrainSettingList.size==0) {
            Tips.showStatus(context,Toast.LENGTH_SHORT,Tips.WARNING,"请选择动作")
            return
        }
        lisenter.let {
            it?.invoke(PlanSettingBean(viewModel.selectTrainSettingList,binding.settingNum.amount,binding.settingCount.amount,binding.settingPower.amount))
        }

    }


}